import os
import shutil
from core.config import PROJECTS_DIR
from core.database import Database

class ProjectManagerCore:
    def __init__(self):
        if not os.path.exists(PROJECTS_DIR):
            os.makedirs(PROJECTS_DIR)

    def list_projects(self):
        return [f for f in os.listdir(PROJECTS_DIR) if os.path.isdir(os.path.join(PROJECTS_DIR, f))]

    def create_project(self, name):
        path = os.path.join(PROJECTS_DIR, name)
        if not os.path.exists(path):
            os.makedirs(path)
            db_path = os.path.join(path, f"{name}.db")
            Database(db_path).close()
        return path

    def delete_project(self, name):
        path = os.path.join(PROJECTS_DIR, name)
        if os.path.exists(path):
            shutil.rmtree(path)

    def get_db_path(self, name):
        return os.path.join(PROJECTS_DIR, name, f"{name}.db")
